import 'package:flutter/material.dart';
import 'package:lianwenke20220712/pic_news.dart';
import 'package:lianwenke20220712/text_news.dart';
import 'package:lianwenke20220712/video_list.dart';
/// FileName 连文科
///
/// @Author/// @Date 2022/7/12 14:47
///
/// @Description 顶部导航栏
class TabWidget extends StatefulWidget {
  const TabWidget({Key key}) : super(key: key);

  @override
  _TabWidgetState createState() => _TabWidgetState();
}

class _TabWidgetState extends State<TabWidget> with SingleTickerProviderStateMixin{
  TabController _controller;
  List<Widget> _tabs;
  List<Widget> _child;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabs = [
      Text('真香'),
      Text('汽车'),
      Text('图片'),
      Text('文字'),
      Text('游戏'),
    ];
    _child = [
      Container(color: Colors.blueGrey,),
      Container(color: Colors.brown,),
      Container(color: Colors.purple,child: PicNewsWidget(),),
      Container(color: Colors.orangeAccent,child: TextNewsWidget(),),
      Container(color: Colors.green,child: VideoListWidget(),),
    ];
    _controller = TabController(length: _tabs.length, vsync: this);
  }
  //避免内存泄漏
  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _controller.dispose();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          Container(
            height: 50,
            child: TabBar(tabs: _tabs,controller: _controller,
            labelStyle: TextStyle(fontSize: 20),labelColor: Colors.black,
            unselectedLabelStyle: TextStyle(fontSize: 16),
            unselectedLabelColor: Colors.black12,),
          ),
          Expanded(child: TabBarView(children: _child,controller: _controller,)),
        ],
      ),
    );
  }
}
